using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodePlex.Resourceful;

namespace CodePlex.SpaceBlock.UI.Controls
{
    public partial class InputboxForm : CodePlex.SpaceBlock.UI.Controls.BaseForm
    {


        private string _customButtonText;
        private Control _customControl;
        private MessageBoxButtons _buttons;


        public InputboxForm()
        {
            InitializeComponent();

            this.MessageBoxButtons = MessageBoxButtons.OKCancel;

            _customButton.Visible = false;
        }

        public string Value
        {
            get
            {
                return _valueBox.Text;
            }
            set
            {
                _valueBox.Text = value;
            }
        }

        public string Title
        {
            get
            {
                return this.Text;   
            }

            set
            {
                this.Text = value;
            }
        }

        public string Prompt
        {
            get
            {
                return _promptLabel.Text;
            }

            set
            {
                _promptLabel.Text = value;
            }
        }

        public string Description
        {
            get
            {
                return _descriptionLabel.Text;
            }

            set
            {
                _descriptionLabel.Text = value;
            }
        }

        public bool HideText
        {
            get
            {
                return _valueBox.UseSystemPasswordChar;
            }
            set
            {
                _valueBox.UseSystemPasswordChar = value;
            }
        }

        public string CustomButtonText
        {
            get
            {
                return _customButtonText;
            }
            set
            {
                _customButtonText = value;

                _customButton.Visible = (_customButtonText != null);
                if (_customButtonText != null)
                {
                    _customButton.Text = _customButtonText;
                }
            }
        }
 
        public Control CustomControl
        {
            get
            {
                return _customControl;
            }

            set
            {
                _customControl = value;

                _customPanel.Controls.Clear();

                if (_customControl == null)
                {
                    _customPanel.TabStop = false;
                } 
                else
                {
                    _customPanel.TabStop = true;
                    _descriptionLabel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                    _promptLabel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                    _valueBox.Anchor = AnchorStyles.Left | AnchorStyles.Top;
                    _customPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                    this.Height += _customControl.Height;

                    UIUtils.FillWith(_customPanel, _customControl);
                } 
            }
        }


        public MessageBoxButtons MessageBoxButtons
        {
            get
            {
                return _buttons;
            }

            set
            {
                _buttons = value;

                // TODO this is gross
                if (_buttons == MessageBoxButtons.YesNo)
                {
                    _promptLabel.Visible = false;
                    _valueBox.Visible = false;
                    _cancelButton.Visible = true;

                    _descriptionLabel.Height = 42 + 20;     

                    _okButton.DialogResult = DialogResult.Yes;
                    _okButton.Text = "Yes";

                    _cancelButton.DialogResult = DialogResult.No;
                    _cancelButton.Text = "No";

                    this.Width = 266;
                    this.Height = 150;
                }
                else if (_buttons == MessageBoxButtons.OK)
                {
                    _promptLabel.Visible = false;
                    _valueBox.Visible = false;
                    _cancelButton.Visible = false;

                    _descriptionLabel.Height = 42 + 20;

                    _okButton.DialogResult = DialogResult.OK;
                    _okButton.Text = "OK";

                    this.Width = 266;
                    this.Height = 150;
                }
                else
                {
                    _promptLabel.Visible = true;
                    _valueBox.Visible = true;
                    _cancelButton.Visible = true;

                    _descriptionLabel.Height = 42;

                    _okButton.DialogResult = DialogResult.OK;
                    _okButton.Text = "OK";

                    _cancelButton.DialogResult = DialogResult.Cancel;
                    _cancelButton.Text = "Cancel";

                    this.Width = 366;
                    this.Height = 153;
                }


            }
        }


        public TextBox ValueBox
        {
            get
            {
                return _valueBox;
            }
        }

        public Button OKButton
        {
            get
            {
                return _okButton;
            }
        }
    }
}

